package mo_gorm

import (
	"MoSkeleton/framework/core/config/properties_db"

	"gorm.io/gorm"
)

// oracle数据库
type MoOracleDb struct {
}

func (m *MoOracleDb) GenDb(dbConfig *properties_db.GeneralDBProvider) (db *gorm.DB) {
	dbProvider := *dbConfig
	if oracleConfig, ok := dbProvider.(*properties_db.Oracle); ok {
		return m.genOracleByConfig(oracleConfig)
	}
	panic("dbConfig is not oracle")
}

func (m *MoOracleDb) genOracleByConfig(dbConfig *properties_db.Oracle) *gorm.DB {
	//if dbConfig.Dbname == "" {
	//	return nil
	//}
	//oracleConfig := oracle.Config{
	//	DSN:                       dbConfig.Dsn(), // DSN data source name
	//	DefaultStringSize:         191,            // string 类型字段的默认长度
	//	SkipInitializeWithVersion: false,          // 根据版本自动配置
	//}
	//if db, err := gorm.Open(oracle.New(oracleConfig), gormConfig(dbConfig.GeneralDB, dbConfig.Prefix, dbConfig.Singular)); err != nil {
	//	panic(err)
	//} else {
	//	sqlDB, _ := db.DB()
	//	sqlDB.SetMaxIdleConns(dbConfig.MaxIdleConns)
	//	sqlDB.SetMaxOpenConns(dbConfig.MaxOpenConns)
	//	return db
	//}
	panic("uncomment up codes")
}
